package test

object test {
  val searchBrands = (orders: Array[String], rules: Array[(String, String)]) => {

    val ordersIter = orders.iterator
    var result = ""
    while (ordersIter.hasNext) {
      val order = ordersIter.next()
      result += search(order,rules)
    }
    val str = result.substring(0,result.length-1).split(",").distinct.toBuffer.toString()
    str.substring(12,str.length-1)
  }
  val search = (order:String,rules: Array[(String, String)])=>{
    val ruleIter = rules.iterator
    var result = ""
    while (ruleIter.hasNext) {
      val rule = ruleIter.next()
      if (order.equals(rule._1)) {
        //brands
        result += rule._2+","
      } else {
        result += ""
      }
    }
    result
  }

  def main(args: Array[String]): Unit = {
    val orders: Array[String] = Array("布莱奥尼西服", "婴儿车","奶粉")
    val rules: Array[(String, String)] = Array(("布莱奥尼西服", "高端人士,商务男士"),
      ("婴儿车", "育儿中"),
      //      ("iPhone8手机壳","高端人士,数码一族,果粉"),
      //      ("iPhone8","高端人士,数码一族,果粉"),
      //      ("婴儿床","育儿中"),
      //      ("spark实战","屌丝,IT人士"),
      //      ("迪奥香水","高端人士,白富美"),
            ("奶粉","育儿中")
      //      ("Hadoop编程指南","屌丝,IT人士")
    )
    val str = searchBrands(orders, rules)
    println(str)


  }
}
